﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tunnel.Tools.FcmsSupport
{
    public class Getplaylist
    {
        private List<DisplayElement> item = new List<DisplayElement>();

        public List<DisplayElement> AddItem(DisplayElement element)
        {
            this.item.Add(element);
            return this.item;
        }

        public void ClearItem()
        {
            this.item.Clear();
        }

        public List<byte> GetPlaylst()
        {
            List<byte> list = new List<byte>();
            string start = "[playlist]\r\nitem_no = ";
            byte[] itmeStringByte = Encoding.ASCII.GetBytes("item");
            List<byte> itmeString = new List<byte>();
            for (int i = 0; i < itmeStringByte.Length; i++)
            {
                itmeString.Add(itmeStringByte[i]);
            }
            List<byte> enterString = new List<byte>();
            byte[] enterStringBytes = Encoding.ASCII.GetBytes("\r\n");
            for (int j = 0; j < enterStringBytes.Length; j++)
            {
                enterString.Add(enterStringBytes[j]);
            }
            foreach (byte num3 in Encoding.ASCII.GetBytes(start))
            {
                list.Add(num3);
            }
            int count = this.item.Count;
            list.Add((byte)(count + 0x30));
            list.AddRange(enterString);
            while (count > 0)
            {
                byte[] buffer7;
                byte[] buffer8;
                list.AddRange(itmeString);
                list.Add((byte)((this.item.Count - count) + 0x30));
                list.Add(0x20);
                list.Add(0x3d);
                list.Add(0x20);
                byte[] buffer4 = Encoding.ASCII.GetBytes(this.item[this.item.Count - count].Delay);
                for (int k = 0; k < buffer4.Length; k++)
                {
                    list.Add(buffer4[k]);
                }
                list.Add(0x2c);
                list.Add(0x20);
                string showType = this.item[this.item.Count - count].ShowType;
                if (showType == null)
                {
                    goto Label_01FA;
                }
                if (!(showType == "立即出现"))
                {
                    if (showType == "上移")
                    {
                        goto Label_01D2;
                    }
                    if (showType == "下移")
                    {
                        goto Label_01DC;
                    }
                    if (showType == "左移")
                    {
                        goto Label_01E6;
                    }
                    if (showType == "右移")
                    {
                        goto Label_01F0;
                    }
                    goto Label_01FA;
                }
                list.Add(0x31);
                goto Label_0202;
                Label_01D2:
                list.Add(50);
                goto Label_0202;
                Label_01DC:
                list.Add(0x33);
                goto Label_0202;
                Label_01E6:
                list.Add(0x34);
                goto Label_0202;
                Label_01F0:
                list.Add(0x35);
                goto Label_0202;
                Label_01FA:
                list.Add(0x31);
                Label_0202:
                list.Add(0x2c);
                list.Add(0x20);
                byte[] buffer5 = Encoding.ASCII.GetBytes(this.item[this.item.Count - count].Speed);
                List<byte> list4 = new List<byte>();
                for (int m = 0; m < buffer5.Length; m++)
                {
                    list4.Add(buffer5[m]);
                }
                list.AddRange(list4);
                list.Add(0x2c);
                list.Add(0x20);
                if (!string.IsNullOrEmpty(this.item[this.item.Count - count].image))
                {
                    list.Add(0x5c);
                    list.Add(0x43);
                    list.AddRange(this.GetXY(this.item[this.item.Count - count].imageX, this.item[this.item.Count - count].imageY));
                    list.Add(0x5c);
                    list.Add(0x42);
                    byte[] buffer6 = Encoding.ASCII.GetBytes(this.item[this.item.Count - count].image);
                    for (int num7 = 0; num7 < buffer6.Length; num7++)
                    {
                        list.Add(buffer6[num7]);
                    }
                }
                list.Add(0x5c);
                list.Add(0x43);
                list.AddRange(this.GetXY(this.item[this.item.Count - count].MsgX, this.item[this.item.Count - count].MsgY));
                list.Add(0x5c);
                list.Add(0x66);
                string font = this.item[this.item.Count - count].Font;
                if (font == null)
                {
                    goto Label_043F;
                }
                if (!(font == "黑体"))
                {
                    if (font == "楷体")
                    {
                        goto Label_0421;
                    }
                    if (font == "宋体")
                    {
                        goto Label_042B;
                    }
                    if (font == "仿宋")
                    {
                        goto Label_0435;
                    }
                    goto Label_043F;
                }
                list.Add(0x68);
                goto Label_0447;
                Label_0421:
                list.Add(0x6b);
                goto Label_0447;
                Label_042B:
                list.Add(0x73);
                goto Label_0447;
                Label_0435:
                list.Add(0x66);
                goto Label_0447;
                Label_043F:
                list.Add(0x73);
                Label_0447:
                buffer7 = Encoding.ASCII.GetBytes(this.item[this.item.Count - count].FontSize);
                List<byte> list5 = new List<byte>();
                for (int n = 0; n < buffer7.Length; n++)
                {
                    list5.Add(buffer7[n]);
                }
                list.AddRange(list5);
                list.Add(0x5c);
                list.Add(0x63);
                string colour = this.item[this.item.Count - count].Colour;
                if (colour == null)
                {
                    goto Label_06AC;
                }
                if (!(colour == "红色"))
                {
                    if (colour == "黄色")
                    {
                        goto Label_0580;
                    }
                    if (colour == "蓝色")
                    {
                        goto Label_05E5;
                    }
                    if (colour == "绿色")
                    {
                        goto Label_064A;
                    }
                    goto Label_06AC;
                }
                list.Add(50);
                list.Add(0x35);
                list.Add(0x35);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                goto Label_070C;
                Label_0580:
                list.Add(50);
                list.Add(0x35);
                list.Add(0x35);
                list.Add(50);
                list.Add(0x35);
                list.Add(0x35);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                goto Label_070C;
                Label_05E5:
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(50);
                list.Add(0x35);
                list.Add(0x35);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                goto Label_070C;
                Label_064A:
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(50);
                list.Add(0x35);
                list.Add(0x35);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                goto Label_070C;
                Label_06AC:
                list.Add(50);
                list.Add(0x35);
                list.Add(0x35);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                list.Add(0x30);
                Label_070C:
                buffer8 = Encoding.Default.GetBytes(this.item[this.item.Count - count].Msg);
                for (int num9 = 0; num9 < buffer8.Length; num9++)
                {
                    list.Add(buffer8[num9]);
                }
                list.AddRange(enterString);
                count--;
            }
            return list;
        }

        private List<byte> GetXY(string x, string y)
        {
            byte[] buffer = new byte[] { 0x30, 0x30, 0x30 };
            byte[] bytes = Encoding.ASCII.GetBytes(x);
            if (bytes.Length == 1)
            {
                buffer[2] = bytes[0];
            }
            else if (bytes.Length == 2)
            {
                buffer[1] = bytes[0];
                buffer[2] = bytes[1];
            }
            else
            {
                buffer[0] = bytes[0];
                buffer[1] = bytes[1];
                buffer[2] = bytes[2];
            }
            byte[] buffer3 = new byte[] { 0x30, 0x30, 0x30 };
            byte[] buffer4 = Encoding.ASCII.GetBytes(y);
            if (buffer4.Length == 1)
            {
                buffer3[2] = buffer4[0];
            }
            else if (buffer4.Length == 2)
            {
                buffer3[1] = buffer4[0];
                buffer3[2] = buffer4[1];
            }
            else
            {
                buffer3[0] = buffer4[0];
                buffer3[1] = buffer4[1];
                buffer3[2] = buffer4[2];
            }
            List<byte> list = new List<byte>();
            for (int i = 0; i < 3; i++)
            {
                list.Add(buffer[i]);
            }
            for (int j = 0; j < 3; j++)
            {
                list.Add(buffer3[j]);
            }
            return list;
        }
    }
}
